﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Drawing;
using System.ComponentModel;

namespace SynoManager.GUI
{
    public class NotifyIconEx : Component
    {
        private NotifyIcon notifyIcon;
        private EventHandler balloonClickHandler = null;

        public NotifyIconEx()
        {
            notifyIcon = new NotifyIcon();
        }

        public NotifyIconEx(IContainer container)
        {
            notifyIcon = new NotifyIcon(container);
            notifyIcon.DoubleClick += notifyIcon_DoubleClick;
            notifyIcon.BalloonTipClicked += notifyIcon_BalloonTipClicked;
        }

        private void notifyIcon_DoubleClick(object sender, EventArgs e)
        {
            if (DoubleClick != null)
                DoubleClick(sender, e);
        }

        void notifyIcon_BalloonTipClicked(object sender, EventArgs e)
        {
            if (balloonClickHandler != null)
                balloonClickHandler(this, e);
        }

        public Icon Icon
        {
            get { return notifyIcon.Icon; }
            set { notifyIcon.Icon = value; }
        }

        public string Text
        {
            get { return notifyIcon.Text; }
            set { notifyIcon.Text = value; }
        }

        public bool Visible
        {
            get { return notifyIcon.Visible; }
            set { notifyIcon.Visible = value; }
        }

        public event EventHandler DoubleClick;

        public ContextMenuStrip ContextMenuStrip
        {
            get { return notifyIcon.ContextMenuStrip; }
            set { notifyIcon.ContextMenuStrip = value; }
        }

        public void ShowBalloonTip(int timeout, string tipTitle, string tipText, ToolTipIcon icon, EventHandler handler)
        {
            // remember the new handler
            balloonClickHandler = handler;

            //show the balloon
            notifyIcon.ShowBalloonTip(timeout, tipTitle, tipText, icon);
        }
    }
}
